package extreme.tddscaffold;

public class GoodsInfo {
    public static final String NORMAL_GOODS = "NormalGoods";
    public static final String AGED_BRIE = "AgedBrie";
    public static final String SULFURAS = "Sulfuras";
    public static final String BACKSTAGE_PASS = "BackstagePass";
    private static int sellIn;
    private static int quantity;

    public GoodsInfo(int sellIn, int quantity) {
        GoodsInfo.sellIn = sellIn;
        GoodsInfo.quantity = quantity;
    }

    public void oneDayPass(String goodsType) {
        if (NORMAL_GOODS.equals(goodsType)) {
            sellInDecrease();
            if (quantity > 0) {
                quantityDecrease();
            }
            if (sellIn < 0 && quantity > 0) {
                quantityDecrease();
            }
        }
        if (AGED_BRIE.equals(goodsType)) {
            sellInDecrease();
            quantityIncrease();
            if (sellIn < 0) {
                quantityIncrease();
            }
            if (quantity > 50) {
                quantity = 50;
            }
        }
        if (BACKSTAGE_PASS.equals(goodsType)) {
            if (sellIn <= 0) {
                quantity = -1;
            }
            if (sellIn > 0 && sellIn <= 5) {
                quantity = quantity + 2;
            }
            if (sellIn > 5 && sellIn <= 10) {
                quantityIncrease();
            }
            sellInDecrease();
            quantityIncrease();
            if (quantity > 50) {
                quantity = 50;
            }
        }
        if (SULFURAS.equals(goodsType)) {
            noChange();
        }
    }

    private void quantityIncrease() {
        quantity = quantity + 1;
    }

    private void sellInDecrease() {
        sellIn = sellIn - 1;
    }

    private void quantityDecrease() {
        quantity = quantity - 1;
    }

    private void noChange() {
    }

    public int getSellIn() {
        return sellIn;
    }

    public int getQuantity() {
        return quantity;
    }
}
